%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 此模板是因王老师有出一本书的需要，本人应邀制作
%% 参考了ElegantBook Template、O'Reilly LaTeX Template等模板
%% auther: 袁爱平
%% E-mail: Apy6631@outlook.com,1540750908@qq.com;
%% base: Tex Live 2023,UTF-8
%% version: AIping v1.0 2024/05/14
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{AIping}[2024/05/14 v1.0 AIping document class]
\setcounter{secnumdepth}{4}
\LoadClass[a4paper,twoside,BCOR1.0cm,DIV11,parskip=full,11pt]{scrbook}

% 模板标识
% 设置标题深度为4(一共四级标题)
% 引用scrbook

%% 预声明
\RequirePackage[T1]{fontenc}
\RequirePackage[utf8]{inputenc}
\RequirePackage{titletoc}     % 目录
\RequirePackage{remreset}     % 计数器设置
\RequirePackage{titlesec}     % 标题
\RequirePackage{xspace}
\RequirePackage{bera}
\RequirePackage{pifont}
\RequirePackage{amssymb}
\RequirePackage[dvipsnames]{xcolor}
\RequirePackage{graphicx}
\RequirePackage{pgf}
\RequirePackage{tikz}
\usetikzlibrary{shapes}
\RequirePackage{ctex}
\RequirePackage{color}
\RequirePackage{scrlayer-scrpage}    % 自定义
\DeclareGraphicsExtensions{.eps,.ps,.png,.jpg,.bmp} % 声明使用图像格式

%% 重新定义标题样式
\addtokomafont{chapter}{\color{black}}
\addtokomafont{section}{\color{black}}
\addtokomafont{subsection}{\color{black}}
\addtokomafont{subsubsection}{\color{black}}

\titleformat{\chapter}[display]
    {\usekomafont{sectioning} \usekomafont{chapter}\filleft}
    {\textcolor[named]{red}\thechapter}
    {-1em}
    {}
\titleformat{\section}[block]
    {\usekomafont{sectioning}\usekomafont{section}
     \tikz[overlay]  \fill[color=red!50,rounded corners=.2ex] (0,-1ex) rectangle (3em,1em);}
    {\textcolor[named]{white}\thesection}
    {2em}
    {}

\titleformat{\subsection}[block]
    {\usekomafont{sectioning}\usekomafont{subsection}
       \tikz[overlay] \fill[color=red!60] (0,-1ex) rectangle (3em,1em);}
    {\textcolor[named]{white}\thesubsection}
    {1em}
    {}

\titleformat{\subsubsection}[block]
    {\usekomafont{sectioning}\usekomafont{subsubsection}
       \tikz[overlay] \fill[color=red!60] (0,-1ex) rectangle (\textwidth,1em);}
    { \thesubsubsection}
    {1em}
    {}